Imports IICBusinessLogic


''' <summary>
''' Returns a student/person object to merge with student object whose id is parameter selectedStudentId
''' </summary>
''' <remarks></remarks>
Public Class UIMergePersonSelector

    Public Function selectMemberToMerge(ByVal selectedStudent As Student) As Student

        Dim ret As Student = Nothing

        If selectedStudent IsNot Nothing Then

            Dim f As New Forms.List.frmStudentListSelect
            f.Size = New Size(Screen.PrimaryScreen.Bounds.Width - 100, _
                              Screen.PrimaryScreen.Bounds.Height - 100)

            f.setMergeStudent(selectedStudent)

            If f.ShowDialog = DialogResult.OK Then
                If f.grdData.SelectedRows.Count <> 1 Then
                    Call winUtils.MsgboxStop("You must select a person row to merge")
                Else
                    Dim studentId As Integer = CInt(f.grdData.SelectedRows(0).Cells("StudentId").Value)
                    If studentId = selectedStudent.StudentId Then
                        Call winUtils.MsgboxStop("You must select another person to merge.")
                    Else
                        ret = StudentDataUtils.findByKey(studentId)

                        If selectedStudent.StudentFullName <> ret.StudentFullName Then
                            Call winUtils.MsgboxStop("Persons to merge must have exactly the same Last Name and First Name.")
                            ret = Nothing
                        End If

                    End If
                End If


            End If
        End If

        Return ret

    End Function

End Class
